package util

import (
	"runtime"

	"code.byted.org/gopkg/logs/v2/log"
)

const (
	MaxStack = 5
)

// CheckPanic checks panics
func CheckPanic() {
	if err := recover(); err != nil {
		for i := 0; i <= MaxStack; i++ {
			if pc, file, line, ok := runtime.Caller(i); ok {
				f := runtime.FuncForPC(pc)
				log.V1.Error("panic error happened, stack:%d, med:%s, file:%s, line:%d, error:%s", i, f.Name(), file, line, err)

			}

		}
		log.V1.Error("panic error happened, error:%s", err)
	}
}
